package fileops

import (
	"fmt"
	"os"
	"strconv"
	"sync"
	"time"
)

var wg = sync.WaitGroup{}

func appendFile(n int, filename string) error {

	file, err := os.OpenFile(filename, os.O_RDWR, 0666)

	if err != nil {
		return err
	}

	for i := 0; i < n; i++ {
		go appendNumsToFile(i, file)
	}

	time.Sleep(10000000)

	return nil

}

func appendNumsToFile(i int, file *os.File) {
	fmt.Printf("【%d】\n", i)
	for j := 0; j < 10; j++ {
		content := "【" + strconv.Itoa(i) + "】" + strconv.Itoa(j+i*10) + "\n"
		_, err := file.WriteString(content)
		if err != nil {
			panic(err)
		}
	}

}
